home *** CD-ROM | disk | FTP | other *** search
-
- Listing 4
-
- const
- HT = chr(9);
- CR = chr(13);
- SPACES = [' ', HT, CR];
-
- function atoi(s : string) : integer;
- var
- c : char;
- i, n : integer;
- neg : boolean;
-
- function next : char;
- begin
- if i < length(s) then
- begin
- inc(i);
- next := s[i];
- end
- else
- next := chr(0);
- end;
-
- begin
- i := 0;
- c := next;
- while c in SPACES do
- c := next;
- neg := FALSE;
- if c = '+' then
- c := next
- else if c = '-' then
- begin
- neg := TRUE;
- c := next;
- end;
- n := 0;
- while c in ['0' .. '9'] do
- begin
- n := 10 * n + ord(s[i]) - ord('0');
- c := next;
- end;
- if neg then
- n := -n;
- atoi := n;
- end;
-
- ----------
-
-